package com.junmeng.retrace;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class StreamUtil {
    /**
     * InputStream转String工具类，返回String
     *
     * @param inputStream
     * @return
     */
    public static String convertStreamToString(InputStream inputStream) throws IOException {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) != -1) {
            result.write(buffer, 0, length);
        }// StandardCharsets.UTF_8.name() > JDK 7
        return result.toString("UTF-8");
    }
}